package com.reih.ContractionTimer.utils;

public class ContractionUtils {
	
	public static String getDuration(Long timeMillis){
//		long hour = timeMillis/(1000*60*60);
//		long minute = (timeMillis-hour*1000*60*60)/(1000*60);
//		long second = (timeMillis-hour*1000*60*60-minute*1000*60)/1000;
//		long millis = (timeMillis-hour*1000*60*60-minute*1000*60-second*1000)/10;
//		return hour+":"+minute+":"+second+"."+millis;
		return getDuration(timeMillis, 4);
	}
	
	public static String getDuration(Long timeMillis,int level){
		StringBuffer sb = new StringBuffer();
		switch (level){
			case 4:
				long millis = (timeMillis%1000)/10;
				sb.append(millis);
			case 3:
				long seconds = (timeMillis%(1000*60))/1000;
				sb.insert(0, ".");
				sb.insert(0, seconds);
			case 2:
				long minute = (timeMillis%(1000*60*60))/(1000*60);
				sb.insert(0, ":");
				sb.insert(0, minute);
			case 1:
				long hour = timeMillis/(1000*60*60);
				sb.insert(0, ":");
				sb.insert(0, hour);
		}
		return sb.toString();
	}

}
